package jeconbond.economic.natural.agent.service;

import java.util.HashMap;
import java.util.Map;

import jeconbond.economic.agent.service.IPostActServiceAgent;
import jeconbond.economic.resources.IResourceType;
import jeconbond.economic.systems.natural.INaturalResourceRedestributionSystem;
import jeconbond.experiment.natural.prodpossibfrontier.process.IConneryExperimentContext;

public class ObserveResourceValueAgent implements IPostActServiceAgent {
	private IResourceType[] types;
	public Map<IResourceType, double[]> type2log = new HashMap<IResourceType, double[]>();
	private INaturalResourceRedestributionSystem nrrs;
	private int[] stepCounter_ptr;
	
	public ObserveResourceValueAgent(
			IConneryExperimentContext experimentContext,
			IResourceType ... types
			) {
		nrrs = experimentContext.getRRS();
		stepCounter_ptr = experimentContext.getNextStepCommander().stepCounter;
		this.types = types;
		int size = experimentContext.getExperimentSettings().stepCount;
		for (IResourceType type : types) {
			type2log.put(type, new double[size]);
		}
	}
	
	@Override
	public void processPostProduceStage() {
		for (IResourceType type : types) {
			double[] typeLog = type2log.get(type);
			double stored = nrrs.howMuchWasStored(type);
			typeLog[stepCounter_ptr[0]] = stored;
		}
	}

	@Override
	public void processPreProduceStage() {}

	@Override
	public void processProduceStage() {}

	public double[] getLog(IResourceType type) {
		return type2log.get(type);
	}
}
